<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>js对象</title>

    <script>
        //构造函数创建对象
        var obj1 = new Object();
        obj1.name = 'lhr';
        obj1.age = 25;


        //字面量创建对象
        //空对象 var obj2 = {}; obj2.name = ............
        //直接写属性
        var obj2 = {
            name : 'lhr',
            age : 25,
            hello : function () {
                alert(this.name);
            }
        }

        //对象调用hello方法，this关键字指向obj2
        obj2.hello();

        var func = obj2.hello;
        //调用func的其实是window对象，这样hello方法的this指向window，此时window.name未定义，alert内容即为空
        func();
    </script>
</head>
<body>

</body>
</html>